home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr25
/
gnuplsrc.zip
/
GCLIENT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-21
|
26KB
|
792 lines
#ifdef INCRCSDATA
static char RCSid[]="$Id: gclient.c,v 1.3 1992/07/26 12:58:42 fearick Exp fearick $" ;
#endif
/****************************************************************************
PROGRAM: GnuShell
MODULE: gclient.c
This file contains the client window procedures for GnuShell
Copyright (c) 1992, Roger Fearick.
All rights reserved
THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT WARRANTIES OF ANY KIND.
Permission is hereby granted for personal, non-commercial use of this
software.You are granted the right to use, modify, and redistribute
it for for non-commercial purposes, provided that all copyright
notices remain intact and all changes are clearly documented.
THE AUTHOR MAKES NO WARRANTY OF ANY KIND WITH RESPECT TO THIS PRODUCT
AND EXPLICITLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY
OR FITNESS FOR ANY PARTICULAR PURPOSE.
****************************************************************************/
/* Update Log
**
* $Log: gclient.c,v $
* Revision 1.3 1992/07/26 12:58:42 fearick
* Clean up from 16-bit command buffer
*
* Revision 1.2 1992/07/26 12:37:10 fearick
* Initial 32-bit version
*
* Revision 1.1 1992/07/25 15:43:51 fearick
* Initial revision
*
*
*/
#define INCL_PM
#define INCL_WIN
#define INCL_DOSMEMMGR
#define INCL_DOSPROCESS
#define INCL_DOSFILEMGR
#define INCL_DOSNMPIPES
#define INCL_DOSSESMGR
#define INCL_DOSSEMAPHORES
#define INCL_DOSMISC
#include <os2.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <process.h>
#include "gnushell.h"
/*==== l o c a l d a t a ==================================================*/
static char szPrintFile[CCHMAXPATH] = { 0 } ; // for printing to files
static HWND hWndstart ; /* used for errors in startup */
static ULONG pidGnu=0L ; /* gnuplot pid */
static HPS hpsScreen ; /* screen pres. space */
static char szFontNameSize[256] ;
static BOOL bLineTypes = FALSE ;
static BOOL bColours = TRUE ;
static HMTX semCommands ;
/* stuff for screen-draw thread control */
static BOOL bExist ;
static BOOL bStopDraw ;
static HEV semDrawDone ;
static HEV semStartDraw ;
/* command buffer */
static int ncalloc = 0 ;
static int ic = 0 ;
static char **commands = NULL ;
/*==== f u n c t i o n s =====================================================*/
MRESULT WmClientCmdProc( HWND , ULONG, MPARAM, MPARAM ) ;
static void ThreadDraw( void ) ;
static void DoPaint( HWND, HPS ) ;
static void Display( void ) ;
void SelectFont( HPS, char *, short, long );
void SpawnGnu( void ) ;
/*==== c o d e ===============================================================*/
MRESULT EXPENTRY DisplayClientWndProc(HWND hWnd, ULONG message, MPARAM mp1, MPARAM mp2)
/*
** Window proc for main window
** -- passes most stuff to active child window via WmClientCmdProc
** -- passes DDE messages to DDEProc
*/
{
HDC hdcScreen ;
SIZEL sizlPage ;
static BYTE abStackGnu[8192] ;
static BYTE abStackDraw[8192] ;
TID tidDraw, tidSpawn ;
ULONG ulCount ;
switch (message) {
case WM_CREATE:
// set initial font
strcpy( szFontNameSize, INITIAL_FONT ) ;
// spawn gnuplot in its own window
hWndstart = hWnd ; /* used in spawngnu for errors */
DosCreateThread( &tidSpawn, (PFNTHREAD)SpawnGnu, 0L, 0L, 8192L ) ;
// create a dc and hps to draw on the screen
hdcScreen = WinOpenWindowDC( hWnd ) ;
sizlPage.cx = 4096 ; sizlPage.cy = 4096 ;
hpsScreen = GpiCreatePS( hab, hdcScreen, &sizlPage,
PU_ARBITRARY|GPIT_MICRO|GPIA_ASSOC) ;
// spawn a thread to do the drawing, controlled by sems
DosCreateMutexSem( NULL, &semCommands, 0L, 0L ) ;
DosCreateEventSem( NULL, &semStartDraw, 0L, 0L ) ;
DosCreateEventSem( NULL, &semDrawDone, 0L, 0L ) ;
DosPostEventSem( semDrawDone ) ; // so we clear screen
DosResetEventSem( semStartDraw, &ulCount ) ;
bStopDraw = FALSE ;
bExist = TRUE ;
DosCreateThread( &tidDraw, (PFNTHREAD)ThreadDraw, 0L, 0L, 8192L ) ;
break ;
case WM_COMMAND:
return WmClientCmdProc( hWnd , message , mp1 , mp2 ) ;
case WM_CLOSE:
if( WinSendMsg( hWnd, WM_USER_PRINT_QBUSY, 0L, 0L ) != 0L ) {
WinMessageBox( HWND_DESKTOP,
hWnd,
"Still printing - not closed",
"Gnushell",
0,
MB_OK | MB_ICONEXCLAMATION ) ;
return 0L ;
}
// kill drawing thread
bExist = FALSE ;
DosWaitEventSem( semDrawDone, SEM_INDEFINITE_WAIT ) ;
// kill gnuplot if still arounsd
if( pidGnu != 0L ) DosStopSession( 0, pidGnu ) ;
return (WinDefWindowProc(hWnd, message, mp1, mp2));
case WM_PAINT:
DoPaint( hWnd, hpsScreen ) ;
break ;
case WM_SIZE :
WinInvalidateRect( hWnd, NULL, TRUE ) ;
break ;
case WM_USER_PRINT_BEGIN:
case WM_USER_PRINT_OK :
case WM_USER_DEV_ERROR :
case WM_USER_PRINT_ERROR :
case WM_USER_PRINT_QBUSY :
return( PrintCmdProc( hWnd, message, mp1, mp2 ) ) ;
case WM_GNUPLOT:
// display the plot
WinInvalidateRect( hWnd, NULL, TRUE ) ;
WinSendMsg( hWnd, WM_PAINT, 0L, 0L ) ;
return 0L ;
case WM_GNU_NOHELP:
// no gnuplot.gih found
WinMessageBox( HWND_DESKTOP,
hWnd,
"Can't find environment variable GNUHELP - no help",
"Gnushell",
0,
MB_OK | MB_ICONEXCLAMATION ) ;
return 0L ;
case WM_GNU_NOEXE:
// no gnuplot.exe found
WinMessageBox( HWND_DESKTOP,
hWnd,
"Can't find Gnuplot exe file !!",
"Gnushell",
0,
MB_OK | MB_ICONEXCLAMATION ) ;
WinPostMsg( hWnd, WM_CLOSE, 0L, 0L ) ;
return 0L ;
default: /* Passes it on if unproccessed */
return (WinDefWindowProc(hWnd, message, mp1, mp2));
}
return (NULL);
}
MRESULT WmClientCmdProc(HWND hWnd, ULONG message, MPARAM mp1, MPARAM mp2)
/*
** Handle client window command (menu) messages
** -- mostly passed on to active child window
**
*/
{
ULONG usDlg ;
extern HWND hApp ;
switch( (USHORT) SHORT1FROMMP( mp1 ) ) {
case IDM_ABOUT : /* show the 'About' box */
WinDlgBox( HWND_DESKTOP,
hwndFrame ,
(PFNWP)About ,
0L,
ID_ABOUT,
NULL ) ;
break ;
case IDM_PRINT:
if( (usDlg = WinDlgBox( HWND_DESKTOP,
hwndFrame ,
(PFNWP)PrintDlgProc ,
0L,
ID_PRINT,
szPrintFile )) != DID_CANCEL ) {
WinPostMsg( hWnd, WM_COMMAND, (MPARAM)usDlg, 0L ) ;
}
break ;
case IDM_LINES:
// change line setting
bLineTypes = !bLineTypes ;
ChangeCheck( hWnd, IDM_LINES, bLineTypes?IDM_LINES:0 ) ;
WinInvalidateRect( hWnd, NULL, TRUE ) ;
break ;
case IDM_COLOURS:
// change colour setting
bColours = !bColours ;
ChangeCheck( hWnd, IDM_COLOURS, bColours?IDM_COLOURS:0 ) ;
WinInvalidateRect( hWnd, NULL, TRUE ) ;
break ;
case IDM_PRINTPIC:
WinPostMsg( hWnd, WM_USER_PRINT_BEGIN, 0L, 0L ) ;
break ;
case IDM_PRINTSETUP:
SetupPrinter( hWnd ) ;
break ;
case IDM_FONTS:
usDlg = WinDlgBox( HWND_DESKTOP,
hwndFrame ,
(PFNWP)QFontDlgProc ,
0L,
IDD_FONTS,
szFontNameSize ) ;
if( usDlg == DID_OK )
WinInvalidateRect( hWnd, NULL, TRUE ) ;
break ;
case IDM_HELPFORHELP:
WinSendMsg(WinQueryHelpInstance(hWnd),
HM_DISPLAY_HELP, 0L, 0L ) ;
return 0L ;
case IDM_EXTENDEDHELP:
WinSendMsg(WinQueryHelpInstance(hWnd),
HM_EXT_HELP, 0L, 0L);
return 0L ;
case IDM_KEYSHELP:
WinSendMsg(WinQueryHelpInstance(hWnd),
HM_KEYS_HELP, 0L, 0L);
return 0L ;
case IDM_HELPINDEX:
WinSendMsg(WinQueryHelpInstance(hWnd),
HM_HELP_INDEX, 0L, 0L);
return 0L ;
default :
return WinDefWindowProc( hWnd, message, mp1, mp2 ) ;
}
return( NULL ) ;
}
static void DoPaint( HWND hWnd, HPS hps )
/*
** Paint the screen with current data
*/
{
RECTL rectClient ;
ULONG ulCount ;
bStopDraw = TRUE ; // stop any drawing in progress and wait for
// thread to signal completion
DosWaitEventSem( semDrawDone, SEM_INDEFINITE_WAIT ) ;
DosResetEventSem( semDrawDone, &ulCount ) ;
WinBeginPaint( hWnd , hps, NULL ) ;
DosPostEventSem( semStartDraw ) ; // start drawing
WinEndPaint( hps ) ;
}
static void ThreadDraw( )
/*
** Thread to draw plot
*/
{
HAB hab ;
RECTL rectClient ;
ULONG ulCount ;
/* initialize and wait until ready to draw */
hab = WinInitialize( 0 ) ;
// DosWaitEventSem( semStartDraw, SEM_INDEFINITE_WAIT ) ;
/* ok - draw until window is destroyed */
while( bExist ) {
// indicate access to window
DosWaitEventSem( semStartDraw, SEM_INDEFINITE_WAIT ) ;
DosResetEventSem( semStartDraw, &ulCount ) ;
// will be set TRUE if we decide to stop in the middle, but now
bStopDraw = FALSE ;
GpiResetPS( hpsScreen, GRES_ALL ) ;
WinQueryWindowRect( hApp, (PRECTL)&rectClient ) ;
GpiSetPageViewport( hpsScreen, &rectClient ) ;
WinFillRect( hpsScreen, &rectClient, CLR_WHITE ) ;
ScalePS( hpsScreen, &rectClient, 0 ) ;
PlotThings( hpsScreen, 0L ) ;
// ok, say that we did it
DosPostEventSem( semDrawDone ) ;
}
WinTerminate( hab ) ;
}
enum JUSTIFY { LEFT, CENTRE, RIGHT } jmode;
void PlotThings( HPS hps, long lColour )
/*
** Plot a spectrum and related graphs on the designated presentation space
**
** Input:
** HPS hps -- presentation space handle of plot ps
** long lColour -- number of physical colours, used mainly by
** printer drivers to set black & white mode.
** If 0, assume screen display
**
** Note: use semaphore to prevent access to command list while
** pipe thread is reallocating the list.
*/
{
int i, lt, ta, col, sl, n, x, y, cx, cy, width ;
int icnow ;
char *str, *buf ;
long sw ;
POINTL ptl ;
POINTL aptl[4] ;
long lCurCol ;
BOOL bBW ;
GRADIENTL grdl ;
BOOL bHorz = TRUE ;
SIZEF sizHor, sizVer ;
/* sometime, make these user modifiable... */
static long lLineTypes[7] = { LINETYPE_SOLID,
LINETYPE_SHORTDASH,
LINETYPE_DOT,
LINETYPE_DASHDOT,
LINETYPE_LONGDASH,
LINETYPE_DOUBLEDOT,
LINETYPE_DASHDOUBLEDOT } ;
static long lCols[15] = { CLR_BLACK,
CLR_DARKGRAY,
CLR_BLUE,
CLR_RED,
CLR_GREEN,
CLR_CYAN,
CLR_PINK,
CLR_YELLOW,
CLR_DARKBLUE,
CLR_DARKRED,
CLR_DARKGREEN,
CLR_DARKCYAN,
CLR_DARKPINK,
CLR_BROWN,
CLR_PALEGRAY } ;
if( lColour== 1 || lColour == 2 ) bBW = TRUE ;
else bBW = FALSE ;
/* loop over accumulated commands from inboard driver */
for( i=0; !bStopDraw && i<ic; i++ ) {
DosRequestMutexSem( semCommands, SEM_INDEFINITE_WAIT ) ;
buf = commands[i];
DosReleaseMutexSem( semCommands ) ;
/* PM_vector(x,y) - draw vector */
if (*buf == 'V') {
sscanf(buf, "V%4d%4d", &x, &y);
ptl.x = (LONG)x ; ptl.y = (LONG)y ;
GpiLine( hps, &ptl ) ;
}
/* PM_move(x,y) - move */
else if (*buf == 'M') {
sscanf(buf, "M%4d%4d", &cx, &cy);
ptl.x = (LONG)cx ; ptl.y = (LONG)cy ;
GpiMove( hps, &ptl ) ;
}
/* PM_put_text(x,y,str) - draw text */
else if (*buf == 'T') {
sscanf(buf, "T%4d%4d", &x, &y);
str = buf + 9; sl = strlen(str) ;
lCurCol = GpiQueryColor( hps ) ;
GpiSetColor( hps, CLR_BLACK ) ;
GpiQueryTextBox( hps, (LONG)strlen( str ), str, 4L, aptl ) ;
if( bHorz ) sw = aptl[3].x ;
else sw = aptl[3].y ;
switch(jmode) {
case LEFT: sw = 0; break;
case CENTRE: sw = -sw/2; break;
case RIGHT: sw = -sw; break;
}
if( bHorz ) {
ptl.x = (LONG)(x+sw) ; ptl.y = (LONG)y ;
}
else {
ptl.x = (LONG)x ; ptl.y = (LONG)(y+sw) ;
}
GpiCharStringAt( hps, &ptl, (LONG) strlen( str ) , str ) ;
GpiSetColor( hps, lCurCol ) ;
}
/* PM_justify_text(mode) - set text justification mode */
else if (*buf == 'J')
sscanf(buf, "J%4d", &jmode);
/* PM_linetype(type) - set line type */
/* mapped to colour */
else if (*buf == 'L') {
sscanf(buf, "L%4d", <);
/* linetype = -2 axes, -1 border, 0 arrows, all to 0 */
col = lt ;
if( lt < 0 ) lt = 0 ;
lt = (lt%8);
col = (col+2)%16 ;
// width = (lt == 0) ? 2 : 0;
if( bLineTypes || bBW ) {
GpiSetLineType( hps, lLineTypes[lt] ) ;
}
if( !bBW ) /* maintain some flexibility here in case we don't want
the model T option */
if( bColours ) GpiSetColor( hps, lCols[col] ) ;
else GpiSetColor( hps, CLR_BLACK ) ;
}
/* PM_text_angle(ang) - set text angle, 0 horz, 1 vert */
else if (*buf == 'A') {
sscanf(buf, "A%4d", &ta);
if( ta == 0 ) {
grdl.x = 0L ; grdl.y = 0L ;
GpiSetCharAngle( hps, &grdl ) ;
if( !bHorz ) {
GpiQueryCharBox( hps, &sizVer ) ;
sizHor.cx = sizVer.cy ; sizHor.cy = sizVer.cx ;
GpiSetCharBox( hps, &sizHor ) ;
bHorz = TRUE ;
}
}
else if( ta == 1 ) {
grdl.x = 0L ; grdl.y = 1L ;
GpiSetCharAngle( hps, &grdl ) ;
if( bHorz ) {
GpiQueryCharBox( hps, &sizHor ) ;
sizVer.cx = sizHor.cy ; sizVer.cy = sizHor.cx ;
GpiSetCharBox( hps, &sizVer ) ;
bHorz = FALSE ;
}
}
else continue ;
}
}
}
short ScalePS( HPS hps, PRECTL prect, USHORT usFlags )
/*
** Get a font to use
** Scale the plot area to world coords for subsequent plotting
*/
{
RECTL rectView, rectClient ;
SIZEL sizePage ;
static char *szFontName ;
static short shFontSize ;
static long lcid = 1L ;
rectClient = *prect ;
sizePage.cx = 4096L ;
sizePage.cy = 4096L ;
sscanf( szFontNameSize, "%d", &shFontSize ) ;
szFontName = strchr( szFontNameSize, '.' ) + 1 ;
rectView.xLeft = 0L ;
rectView.xRight = sizePage.cx ;
rectView.yBottom = 0L ; rectView.yTop = sizePage.cy ;
GpiSetPS( hps, &sizePage, PU_ARBITRARY ) ;
GpiSetPageViewport( hps, &rectClient ) ;
SelectFont( hps, szFontName, shFontSize, lcid ) ;
GpiSetGraphicsField( hps, &rectView ) ;
return 0 ;
}
void SelectFont( HPS hps, char *szFont, short shPointSize, long lcid )
/*
** Select a named and sized outline (adobe) font
*/
{
HDC hdc ;
static FATTRS fat ;
LONG xDeviceRes, yDeviceRes ;
POINTL ptlFont ;
SIZEF sizfx ;
fat.usRecordLength = sizeof fat ;
fat.fsSelection = 0 ;
fat.lMatch = 0 ;
fat.idRegistry = 0 ;
fat.usCodePage = GpiQueryCp (hps) ;
fat.lMaxBaselineExt = 0 ;
fat.lAveCharWidth = 0 ;
fat.fsType = 0 ;
fat.fsFontUse = FATTR_FONTUSE_OUTLINE |
FATTR_FONTUSE_TRANSFORMABLE ;
strcpy (fat.szFacename, szFont) ;
GpiCreateLogFont (hps, NULL, lcid, &fat) ;
GpiSetCharSet( hps, lcid ) ;
hdc = GpiQueryDevice (hps) ;
DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION, 1L, &xDeviceRes) ;
DevQueryCaps (hdc, CAPS_VERTICAL_RESOLUTION, 1L, &yDeviceRes) ;
// Find desired font size in pixels
ptlFont.x = 254L * (long)shPointSize * xDeviceRes / 720000L ;
ptlFont.y = 254L * (long)shPointSize * yDeviceRes / 720000L ;
// Convert to page units
GpiConvert (hps, CVTC_DEVICE, CVTC_PAGE, 1L, &ptlFont) ;
// Set the character box
sizfx.cx = MAKEFIXED (ptlFont.x, 0) ;
sizfx.cy = MAKEFIXED (ptlFont.y, 0) ;
GpiSetCharBox (hps, &sizfx) ;
}
void SpawnGnu()
/*
** Spawn gnuplot in a command-line window and open a named pipe
** for graphics commands
** Error messages must be posted, not sent, as this is a new thread.
** (We could open our own message queue for such, but why bother?).
*/
{
HPIPE hRead ;
static char buf[130] ;
char *szEnv ;
char *szFileBuf ;
char *envpt, *pget ;
USHORT pid, rc, usErr ;
ULONG cbR ;
STARTDATA start ;
USHORT i ;
PID ppid ;
char buff[2] ;
DosEnterCritSec() ;
szFileBuf = malloc(CCHMAXPATHCOMP) ;
DosExitCritSec() ;
if( szFileBuf == NULL ) return ;
// 2048 bytes for environment should suffice,
// but need better allocation method
DosEnterCritSec() ;
szEnv = malloc(2048) ;
DosExitCritSec() ;
if( szEnv == NULL ) return ;
/* open a named pipe for communication with gnuplot */
rc = DosCreateNPipe( GNUPIPE,
&hRead,
NP_ACCESS_DUPLEX|NP_NOINHERIT|NP_NOWRITEBEHIND ,
1|NP_WAIT|NP_READMODE_BYTE|NP_TYPE_BYTE,
1024,
1024,
60000L) ;
/* spawn gnuplot */
/* first, build the environment: will use existing if
available, else attempts to make its own */
strcpy( szEnv, ENVGNUHELP ) ; strcat( szEnv, "=" ) ;
if( ( envpt = getenv( ENVGNUHELP ) ) != NULL )
strcat( szEnv, envpt ) ;
else {
rc = DosSearchPath( SEARCH_CUR_DIRECTORY, /* try here */
"PATH",
GNUHELPFILE,
szFileBuf,
256L ) ;
if( rc == 0 ) {
strcat( szEnv, szFileBuf ) ;
}
else
WinPostMsg( hWndstart, WM_GNU_NOHELP, 0L, 0L ) ;
}
envpt = szEnv + strlen( szEnv ) +1 ;
strcpy( envpt, GNUTERMINIT ) ;
envpt = envpt + strlen( envpt ) +1 ;
strcpy( envpt, "COMSPEC=" ) ;
envpt = envpt + strlen( envpt ) ;
strcat( envpt, getenv( "COMSPEC" ) ) ;
envpt = envpt + strlen( envpt ) +1 ;
strcpy( envpt, ENVGNUPLOT ) ; strcat( envpt, "=" ) ;
if( (pget=getenv( ENVGNUPLOT ))!= NULL )
strcat( envpt, pget ) ;
else
strcat( envpt, getcwd( szFileBuf, 256 ) ) ;
envpt = envpt + strlen( envpt ) +1 ;
strcpy( envpt, "PATH=" ) ; // need path for execed command shells
if( (pget=getenv( "PATH" ))!= NULL )
strcat( envpt, pget ) ;
envpt = envpt + strlen( envpt ) +1 ;
*envpt = 0 ;
/* find exe file */
rc = DosSearchPath( SEARCH_ENVIRONMENT, /* search gnuplot env */
ENVGNUPLOT,
GNUEXEFILE,
szFileBuf,
256L ) ;
if( rc != 0 )
rc = DosSearchPath( SEARCH_CUR_DIRECTORY|SEARCH_ENVIRONMENT, /* then try path */
"PATH",
GNUEXEFILE,
szFileBuf,
256L ) ;
if( rc != 0 ) { /* can't fine gnuplot exe ! */
WinPostMsg( hWndstart, WM_GNU_NOEXE, 0L, 0L ) ;
return ;
}
/* start a new windowed session on the desktop */
start.Length = sizeof(STARTDATA) ;
start.Related = TRUE ;
start.FgBg = FALSE ;
start.TraceOpt = 0 ;
start.PgmTitle = "Gnushell: Commands" ;
start.PgmName = szFileBuf ;
start.PgmInputs = "" ;
start.TermQ = "" ;
start.Environment = szEnv ;
start.InheritOpt = 0 ;
start.SessionType = 2 ;
start.IconFile = "" ;
start.PgmHandle = 0L ;
start.PgmControl = 32768 ;
start.InitXPos = 0;//20;
start.InitYPos = 0;//20;
start.InitXSize = 0;//600;
start.InitYSize = 0;//200;
start.ObjectBuffer = NULL ;
start.ObjectBuffLen = 0L ;
DosStartSession( &start, &pidGnu, &ppid ) ;
DosEnterCritSec() ;
free( szFileBuf ) ;
free( szEnv ) ;
DosExitCritSec() ;
/* attach to gnuplot */
DosConnectNPipe( hRead ) ;
/* store graphics commands */
/* use semaphore to prevent problems with drawing while reallocating
the command buffers */
while ( 1) {
i = 0 ;
while((usErr=DosRead(hRead,buff, 1, &cbR))==0) {
if( buff[0] == 0x0a || buff[0] == 0x0d ) {
buf[i] = 0 ; break ; }
else buf[i++] = buff[0] ;
}
if( usErr != 0 ) break ;
if (*buf == 'G') { /* enter graphics mode */
/* wait for access to command list and lock it */
DosRequestMutexSem( semCommands, SEM_INDEFINITE_WAIT ) ;
DosEnterCritSec() ;
if (commands!=NULL) { // delete all old commands and prepare for new
int i;
for(i=0; i<=ic ;i++ )
free(commands[i]);
free(commands);
}
commands = NULL; ncalloc = 0; ic = 0 ;
DosExitCritSec() ;
DosReleaseMutexSem( semCommands ) ;
}
else if (*buf == 'E') { Display() ; } /* plot graph */
else if (*buf == 'R') { break ; } /* leave gnushell */
/* otherwise store command, allocating memory if necc.
using really messy scheme to get round 64K limit to
realloc [must rewrite for 2.0 !] */
else {
if (ic >= ncalloc) {
DosRequestMutexSem( semCommands, SEM_INDEFINITE_WAIT ) ;
DosEnterCritSec() ;
ncalloc = ncalloc + 4096 ;
commands = (char**)realloc(commands, ncalloc*sizeof(char*)) ;
DosExitCritSec() ;
DosReleaseMutexSem( semCommands ) ;
}
commands[ic] = strdup(buf);
ic++ ;
}
}
pidGnu = 0 ; /* gnuplot has shut down ... */
WinPostMsg( hApp, WM_CLOSE, 0L, 0L ) ;
}
static void Display()
/*
** Display gnuplot results
** -- must post message as this thread is not drawing thread
*/
{
WinPostMsg( hApp, WM_GNUPLOT, 0L, 0L ) ;
}